package com.qys.livesMall.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qys.livesMall.common.constants.Constants;
import com.qys.livesMall.common.exception.QysException;
import com.qys.livesMall.common.exception.enums.ExceptionEnum;
import com.qys.livesMall.framework.view.Paging;
import com.qys.livesMall.framework.view.QysPage;
import com.qys.livesMall.system.modal.dto.ThinkTanksInfoQuery;
import com.qys.livesMall.system.modal.entity.SysThinkTanksInfo;
import com.qys.livesMall.system.mapper.SysThinkTanksInfoMapper;
import com.qys.livesMall.system.service.SysThinkTanksInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统智库问答 服务实现类
 * </p>
 *
 * @author
 * @since 2023-10-31
 */
@Service
public class SysThinkTanksInfoServiceImpl extends ServiceImpl<SysThinkTanksInfoMapper, SysThinkTanksInfo> implements SysThinkTanksInfoService {

    @Autowired
    private SysThinkTanksInfoMapper thinkTanksInfoMapper;
    @Override
    public QysPage<SysThinkTanksInfo> search(ThinkTanksInfoQuery search) {
        Paging<SysThinkTanksInfo> list=thinkTanksInfoMapper.search(new Paging<>(search));
        return QysPage.to(list);
    }

    @Override
    public void add(SysThinkTanksInfo thinkTanksInfo) {
        if (thinkTanksInfo.getTypeId()==null||StringUtils.isBlank(thinkTanksInfo.getQuestion())){
            throw new QysException(ExceptionEnum.PARAM_IS_ERROR);
        }
        thinkTanksInfo.setDeleted(Constants.YesNoInt.NO);
        save(thinkTanksInfo);
    }

    @Override
    public void edit(SysThinkTanksInfo thinkTanksInfo) {
        if (thinkTanksInfo.getId()==null){
            throw new QysException(ExceptionEnum.PARAM_IS_ERROR);
        }
        updateById(thinkTanksInfo);
    }

    @Override
    public void del(Integer id) {
        if (id==null){
            throw new QysException(ExceptionEnum.PARAM_IS_ERROR);
        }
        SysThinkTanksInfo info=getById(id);
        info.setDeleted(Constants.YesNoInt.YES);
        updateById(info);
    }

    public void delByType(Integer typeId){
        LambdaQueryWrapper<SysThinkTanksInfo> wq=new LambdaQueryWrapper<>();
        wq.eq(SysThinkTanksInfo::getTypeId,typeId);
        remove(wq);
    }
}
